<?php
/**
 * Модель tag
 * 
 * Класс модели
 * @author Anton Zavidov
 * @package myLiveShop
 */

/**
 * Модель tag
 *
 */
class ModelTag extends Model {
	
	const TABLE				= 'tag';
	const F_TAG_ID	 		= 'tag_id';
	const F_USER_ID  		= 'user_id';
	const F_TITLE 	 		= 'title';
	const F_COUNT_ELEMENTS	= 'count_elements';
	const F_PERCENT_COUNT_ELEMENTS	= 'percent_count_elements';
	
	public function __construct($className=null){
		parent::__construct(__CLASS__);
		$this->name='tag';
		$this->id_field=array(self::F_TAG_ID);
		$this->fields=array(
			self::TABLE.DOT.self::F_TAG_ID 			=> new Field($this,self::F_TAG_ID,self::TABLE,array(
										'lenght'=>5,
										'auto'=>true)),
			self::TABLE.DOT.self::F_USER_ID 		=> new Field($this,self::F_USER_ID,self::TABLE,array(
										'important'=>true,
										'lenght'=>2,
										'join_table'=>'user')),
			self::TABLE.DOT.self::F_TITLE 			=> new Field($this,self::F_TITLE,self::TABLE,array(
										'type'=>Field::TYPE_STRING,
										'lenght'=>255,
										'important'=>true)),
			self::TABLE.DOT.self::F_COUNT_ELEMENTS 	=> new Field($this,self::F_COUNT_ELEMENTS,self::TABLE,array(
										'lenght'=>5)),
			self::TABLE.DOT.self::F_PERCENT_COUNT_ELEMENTS=> new Field($this,self::F_PERCENT_COUNT_ELEMENTS,self::TABLE,array(
										'field_query'=>'(100/(SELECT SUM('.self::F_COUNT_ELEMENTS.') FROM '.self::TABLE.'))*'.DB::apostrof(self::TABLE.DOT.self::F_COUNT_ELEMENTS),
										'lenght'=>3))
		);
	}
}